package com.itcs.app.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itcs.app.service.AccountService;
import com.itcs.app.util.Codes;
import com.itcs.trading.mapper.UserAccountInfoMapper;
import com.itcs.trading.mapper.UserBankInfoMapper;
import com.itcs.trading.mapper.UserCashinOpHisMapper;
import com.itcs.trading.mapper.UserInfoMapper;
import com.itcs.trading.model.UserBankInfo;

@Service
public class AccountServiceImol implements AccountService {
	
	private static Logger logger = LoggerFactory.getLogger(AccountServiceImol.class);
	@Autowired
	private UserInfoMapper userInfoMapper;
	@Autowired
	private UserBankInfoMapper userBankInfoMapper;
	@Autowired
	UserCashinOpHisMapper userCashinOpHisMapper;
	@Autowired
	private UserAccountInfoMapper UserAccountInfoMapper;
	
	/**
	 * 绑定银行卡
	 * @param param
	 * @return 
	 * @author 罗晨曦
	 * 
	 */
	@Override
	public Map<String, Object> addBankCard(Map<String, Object> param) {
		Map<String, Object> resp = new HashMap<>();

		//user_customer_info
		
		//user_bank_info
		UserBankInfo userBankInfo = new UserBankInfo();
		userBankInfo.setUserId((Long) param.get("userId"));
		userBankInfo.setBankcardNo((String) param.get("bankcardNo"));
		//
		userBankInfo.setBankName((String) param.get("bankName"));//ping++返回信息中没有
		userBankInfo.setBankcardState((Long)param.get("bankcardState"));//ping++返回信息中没有
		userBankInfo.setBankcardType((Byte)param.get("bankcardType"));//ping++返回信息中没有
		
		int n = userBankInfoMapper.insert(userBankInfo);
		if(n==1) {
			resp.put(Codes.CODE, Codes.SUCCESS);
		}else {
			resp.put(Codes.CODE, 300);
		}
		return resp;
	}

	/**
	 * 银行卡列表
	 * @param param
	 * @return
	 * @author 罗晨曦
	 */
	@Override
	public List<Map<String, Object>> findBankCard(Long param) {
		List<Map<String, Object>> list = userBankInfoMapper.findBankCard(param);
		return list;
	}

	
	/**
	 * 提现记录列表
	 * @param id
	 * @param pageSize
	 * @param pageIndex
	 * @return
	 * @author 罗晨曦
	 */
	@Override
	public List<Map<String, Object>> findWithdrawals(Long id, Integer pageSize, Integer pageIndex) {
		//id,pageSize*(pageIndex-1),pageSize
		logger.info("id:{},pageSize:{},pageIndex{}",id,pageSize,pageIndex);
		List<Map<String, Object>> list = userCashinOpHisMapper.findWithdrawals(id,pageSize*(pageIndex-1),pageSize);
		return list;
	}

	/**
	 * 用户资金
	 * @param id
	 * @return
	 * @author 罗晨曦
	 */
	@Override
	public List<Map<String, Object>> wallet(Long id) {
		List<Map<String, Object>> list = UserAccountInfoMapper.wallet(id);
		return list;
	}

}
